<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/6 23:58
 */

namespace module\ai\library\channel\platform;

use module\ai\library\channel\abstract\Platform;
use mof\Model;

class KimiPlatform extends Platform
{
    protected string $regUrl = 'https://platform.moonshot.cn/';

    public static function getName(): string
    {
        return 'Kimi';
    }

    public static function getFlag(): string
    {
        return 'kimi';
    }

    public static function models(): array
    {
        return [
            'moonshot-v1-auto' => 'moonshot-v1-auto',
            'moonshot-v1-8k'   => 'moonshot-v1-8k',
            'moonshot-v1-32k'  => 'moonshot-v1-32k',
            'moonshot-v1-128k' => 'moonshot-v1-128k',
        ];
    }

    public function getConfigForm(Model $model = null): array
    {
        return [
            ...parent::getConfigForm($model),
            [
                "label" => "max_tokens",
                "prop"  => "config.max_tokens",
                "value" => $model['config']['max_tokens'] ?? '',
                "intro" => "聊天完成时生成的最大 token 数",
                "tip"   => "最大token数"
            ],
            [
                "label" => "temperature",
                "prop"  => "config.temperature",
                "value" => $model['config']['temperature'] ?? '',
                "intro" => "使用什么采样温度，介于 0 和 1 之间。",
                "tip"   => "较高的值（如 0.7）将使输出更加随机，而较低的值（如 0.2）将使其更加集中和确定性。"
            ],
            [
                "label" => "top_p",
                "prop"  => "config.top_p",
                "value" => $model['config']['top_p'] ?? '',
                "intro" => "概率阈值。生成时，核采样方法的概率阈值。取值范围为（0,1.0]",
                "tip"   => "取值越大，生成的随机性越高；取值越低，生成的随机性越低。"
            ],
            [
                "label" => "presence_penalty",
                "prop"  => "config.presence_penalty",
                "value" => $model['config']['presence_penalty'] ?? '',
                "intro" => "存在惩罚，介于-2.0到2.0之间的数字。",
                "tip"   => "正值会根据新生成的词汇是否出现在文本中来进行惩罚，增加模型讨论新话题的可能性"
            ],
            [
                "label" => "frequency_penalty",
                "prop"  => "config.frequency_penalty",
                "value" => $model['config']['frequency_penalty'] ?? '',
                "intro" => "频率惩罚，介于-2.0到2.0之间的数字。",
                "tip"   => "正值会根据新生成的词汇在文本中现有的频率来进行惩罚，减少模型一字不差重复同样话语的可能性"
            ],
        ];
    }

    public function getKeyColumns(): array
    {
        return [
            'api_key' => [
                'label'  => 'Api-Key',
                'secret' => true,
            ]
        ];
    }

}